package com.ruoyi.system.kafkaLinterens;


import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.log.service.AsyncLogService;
import com.ruoyi.system.api.domain.SysOperLog;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.listener.AcknowledgingMessageListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class LogkafkaLinterens implements AcknowledgingMessageListener<String,String> {

    @Autowired
    private AsyncLogService asyncLogService;

    @Override
    @KafkaListener(topics = "1911A")
    public void onMessage(ConsumerRecord<String, String> data, Acknowledgment acknowledgment) {
        String value = data.value();
        System.err.println("value:    "+value);
        if (data.key().equals("add")){
            SysOperLog sysOperLog = JSON.parseObject(value, SysOperLog.class);
            asyncLogService.saveSysLog(sysOperLog);
        }

        acknowledgment.acknowledge();
    }
}
